=begin pod :kind("Type") :subkind("class") :category("basic")

=TITLE class IntStr

=SUBTITLE Dual value integer and string

    class IntStr is Allomorph is Int { }

C<IntStr> is a dual value type, a subclass of both
L«C<Allomorph>|/type/Allomorph», hence L«C<Str>|/type/Str», and
L«C<Int>|/type/Int».

See L«C<Allomorph>|/type/Allomorph» for further details.

=begin code
my $int-str = <42>;
say $int-str.^name;     # OUTPUT: «IntStr␤»

my Int $int = $int-str; # OK!
my Str $str = $int-str; # OK!

# ∈ operator cares about object identity
say 42 ∈ <42  55  1>;   # OUTPUT: «False␤»
=end code

=head1 Methods

=head2 method new

    method new(Int $i, Str $s)

The constructor requires both the C<Int> and the C<Str> value, when constructing one
directly the values can be whatever is required:

    my $f = IntStr.new(42, "forty two");
    say +$f; # OUTPUT: «42␤»
    say ~$f; # OUTPUT: «"forty two"␤»

=head2 method Int

    method Int

Returns the integer value of the C<IntStr>.

=head2 method Numeric

Defined as:

    multi method Numeric(IntStr:D: --> Int:D)
    multi method Numeric(IntStr:U: --> Int:D)

The C<:D> variant returns the numeric portion of the invocant. The C<:U> variant issues
a warning about using an uninitialized value in numeric context and then returns value C<0>.

=head2 method Real

Defined as:

    multi method Real(IntStr:D: --> Int:D)
    multi method Real(IntStr:U: --> Int:D)

The C<:D> variant returns the numeric portion of the invocant. The C<:U> variant issues
a warning about using an uninitialized value in numeric context and then returns value C<0>.

=head1 Operators

=head2 infix C«===»

    multi sub infix:<===>(IntStr:D $a, IntStr:D $b)

C<IntStr> Value identity operator. Returns C<True> if the C<Int>
values of C<$a> and C<$b> are L<identical|/routine/===> and their C<Str>
values are also L<identical|/routine/===>. Returns C<False> otherwise.

=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
